/**
 * Created by huiran on 2017/4/25.
 */
//	实时监控浏览器窗口大小
function shouji() {
    $('.tans').css('display','none');
    // alert(320);
    $('.xuanfu').css('display','none');
    $('.yusuan').css('display','none');
    $('#photo-big').css('height','50%');
    $('.right-arrow').css('visibility','hidden');
    $('.left-arrow').css('visibility','hidden');
    $('.xuanfu.xuanfus').css('display','block');
}
function diannao() {
    $('.xuanfu').css('display','block');
    $('#photo-big').css('height','80%');
    $('.right-arrow').css('visibility','visible');
    $('.left-arrow').css('visibility','visible');
    $('#layerslider-container-fw').css('height','100%');
    $('.tans').css('display','block').addClass('animated slideInUp');
    $('.yusuan').css('display','block').animate({
        top:'20%'
    },500);
    $('.xuanfu.xuanfus').css('display','none');
}
window.onresize = function () {
    if (document.body.clientWidth <= 320){
        $('.ls-inner').css('height','200px');
        $('.bbb').css('height','200px');
        shouji();
    }else  if (document.body.clientWidth <= 480 ){
        $('.ls-inner').css('height','280px');
        $('.bbb').css('height','280px');
       shouji();
    }else if(document.body.clientWidth <=767 ){
        $('.ls-inner').css('height','320px');
        $('.bbb').css('height','320px');
       shouji();
    }else if(document.body.clientWidth <=980){
        $('.ls-inner').css('height','550px');
        $('.bbb').css('height','550px');
       shouji();
    }else if(document.body.clientWidth <= 1200){
        $('.ls-inner').css('height','660px');
        $('.bbb').css('height','660px');
       diannao();
    }else if(document.body.clientWidth > 1200){
        $('.ls-inner').css('height','900px');
        $('.bbb').css('height','900px');
        diannao();
    }
};
//加载特效
$(document).ready(
    function () {
        if(document.body.clientWidth >=1000){

            if(document.body.clientWidth <= 1200){
                $('.ls-inner').css('height','660px');
                $('.bbb').css('height','660px');
                diannao();
            }else if(document.body.clientWidth > 1200){
                $('.ls-inner').css('height','900px');
                $('.bbb').css('height','900px');
                diannao();
            }
        }else if(document.body.clientWidth < 1000){    //手机端
            $('.tans').css('display','none');
            $('.yusuan').css('display','none');
            if (document.body.clientWidth <= 320){
                $('.ls-inner').css('height','200px');
                $('.bbb').css('height','200px');
                $('#layerslider-container-fw').css('height','100%');
                shouji();
            }else  if (document.body.clientWidth <= 480 ){
                $('.ls-inner').css('height','280px');
                $('.bbb').css('height','280px');
                $('#layerslider-container-fw').css('height','100%');
                shouji();
            }else if(document.body.clientWidth <=767 ){
                $('.ls-inner').css('height','320px');
                $('.bbb').css('height','320px');
                $('#layerslider-container-fw').css('height','100%');
                shouji();
            }else if(document.body.clientWidth <=980){
                $('.ls-inner').css('height','550px');
                $('.bbb').css('height','550px');
                $('#layerslider-container-fw').css('height','100%');
                shouji();
            }
        }
    }
);

function xians() {
    $('.tans').css('display','block').addClass('animated slideInUp');
    $('.yusuan').css('display','block').animate({
        top:'20%'
    },500)
}
function xiaoshi() {
    $('.yusuan').css('display','none');
}
function xianshen() {
    $('.yusuan').css('display','block');
}
//页面滚动
document.onscroll = function () {

    if ($(window).height() + $(document).scrollTop() >= $('#guding').offset().top+810) {
        $('#guding').addClass('guding')
    }
    if ($(window).height() + $(document).scrollTop() >= $('.inde-cont1 ').offset().top) {
        $('.inde-cont1 .inde-cont3').addClass('animated zoomIn');
    }
    if ($(window).height() + $(document).scrollTop() >= ($('.team ').offset().top+ 300)) {
        $('.team .inde-cont3').addClass('animated zoomIn');
        $('#slideBox').addClass('animated flipInY');
    }
    if ($(window).height() + $(document).scrollTop() >= ($('.design').offset().top+ 300)) {
        $('.design .inde-cont3').addClass('animated zoomIn');
        if($(window).height() + $(document).scrollTop() >= ($('.yang-1').offset().top)){
            $('.yang-1').addClass('animated zoomIn');
        }
        if($(window).height() + $(document).scrollTop() >= ($('.yang-2').offset().top)){
            $('.yang-2').addClass('animated zoomIn');
        }
        if($(window).height() + $(document).scrollTop() >= ($('.yang-3').offset().top)){
            $('.yang-3').addClass('animated zoomIn');
        }
        if($(window).height() + $(document).scrollTop() >= ($('.yang-4').offset().top)){
            $('.yang-4').addClass('animated zoomIn');
        }
        if($(window).height() + $(document).scrollTop() >= ($('.yang-5').offset().top)){
            $('.yang-5').addClass('animated zoomIn');
        }
    }

    if ($(window).height() + $(document).scrollTop() >= ($('.about').offset().top+ 300)){
        $('.about .row').addClass('animated zoomIn');
        $('.about .row .col-md-12').addClass('animated flipInY')
    }
    if ($(window).height() + $(document).scrollTop() >= ($('.news').offset().top + 300)){
        $('.rows .col-md-12').addClass('animated zoomIn');
        if($(window).height() + $(document).scrollTop() >= ($('.diyi').offset().top)){
            $('.rowss .col-md-12 .news-main.diyi').addClass('animated zoomIn');
        }
        if($(window).height() + $(document).scrollTop() >= ($('.disan').offset().top)){
            $('.news .col-md-5 .news-main.disan').addClass('animated zoomIn');
        }
        if($(window).height() + $(document).scrollTop() >= ($('.dier').offset().top)){
            $('.rowss .col-md-12 .news-main.dier').addClass('animated zoomIn');
        }
        if($(window).height() + $(document).scrollTop() >= ($('.disi').offset().top)){
            $('.news .col-md-5 .news-main.disi').addClass('animated zoomIn');
        }
    }
};
// 遮罩层的大小永远都是100%
function setScreenWH () {
    var w = $(window).width() + $(document).scrollLeft();
    var h = $(window).height() + $(document).scrollTop();
    $('#screen').width(w).height(h);

}
// 弹出框永远在屏幕中间的位置
function setCenter () {
    var left = ($(window).width() - $('#photo-big').width())/2 + $(document).scrollLeft();
    var top = ($(window).height() - $('#photo-big').height())/2 + $(document).scrollTop();

    $('#photo-big').css({top:top,left:left});
}
setScreenWH();
setCenter();
// 当页面大小发生变化或者滚动时调用这两个方法
$(window).on('resize',setScreenWH);
$(document).on('scroll',setScreenWH);
$(window).on('resize',setCenter);
$(document).on('scroll',setCenter);
//点击出大图
$('.row.pro div a').click(function () {
    // 显示遮罩层
    $('#screen').css('display','block').animate({
        opacity:0.6
    },500);
    // 显示图片弹出框
    $('#photo-big').css('display','block');

    document.body.style.overflow = 'hidden';
    document.documentElement.style.overflow = 'hidden';

    // 加载图片(预加载)
    // 创建一个image对象，来保存大图片的地址，
    // 当大图片加载完毕后，再把loading的图片替换掉，并调整图片的位置
    var img = new Image();
    img.src = $(this).siblings('img').attr('xsrc');//预加载
    $(img).on('load',function () {
        //图片加载完毕之后,显示大图
        $('#photo-big .big img').attr('src',img.src)
        // .animate({opacity:1})
            .css({width:'100%',height:'99.5%',top:0});
    });

    // 当前显示在弹出框的img所在的dl标签
    var current_dl = $(this).parent();
    previousLoadImage(current_dl);
});
// 点击关闭
$('#photo-big .close').click(function () {
    //隐藏遮罩层和弹出框
    $('#screen').css('display','none').animate({
        opacity:0
    },500);
    $('#photo-big').css('display','none');

    document.body.style.overflow = 'auto';
    document.documentElement.style.overflow = 'auto';

    // 弹出框关闭后，把弹出框加载的图片恢复成loading.gif
    $('#photo-big .big img').attr('src','images/loading.gif')
        .css({width:32,height:32,top:200});
});
// 显示左边箭头
$('#photo-big .big .left').hover(function () {
    $('#photo-big .big .left-arrow').stop().animate({
        opacity:0.5
    },'fast');
},function () {
    $('#photo-big .big .left-arrow').stop().animate({
        opacity:0
    },'fast');
});
// 显示右边箭头
$('#photo-big .big .right').hover(function () {
    $('#photo-big .big .right-arrow').stop().animate({
        opacity:0.5
    },'fast');
},function () {
    $('#photo-big .big .right-arrow').stop().animate({
        opacity:0
    },'fast');
});

// 点击图片的左边切换成上一张图    索引每次-1
$('#photo-big .big span.left').click(function () {

    // 预加载图片时显示loading.gif
    $('#photo-big .big img').attr('src','images/loading.gif')
        .css({width:32,height:32,top:200});

    // 点击加载上一张图
    var prev_img = new Image();
    prev_img.src = $(this).attr('src');
    $(prev_img).on('load',function () {
        // 图片预加载完毕后，显示在弹出框的img上
        $('#photo-big .big img').attr('src',prev_img.src)
            .css({width:'100%',height:'99.5%',top:0});
    });

    // 获取当前在弹出框显示的图片所在的dl
    // 获取相邻的上一张图片所在的dl的索引值，每点击一次span减1
    var prev_index = $('#photo-big .big img').attr('index')==0
        ? $('.wait-load').length-1
        : parseInt($('#photo-big .big img').attr('index'))-1;
    // 获取相邻的上一个dl
    var prev_dl = $('.row.pro div').eq(prev_index);
    previousLoadImage(prev_dl);
});

// 点击图片的右边切换成下一张图	索引每次+1
$('#photo-big .big span.right').click(function () {
    // 先加载loading.gif
    $('#photo-big .big img').attr('src','images/loading.gif')
        .css({width:32,height:32,top:200});

    // 预加载下一张图片
    var next_img = new Image();
    next_img.src = $(this).attr('src');
    $(next_img).on('load',function () {
        $('#photo-big .big img').attr('src',next_img.src)
            .css({width:'100%',height:'99.5%',top:0});
    })

    // 找到当前显示在弹出框的img所在的dl
    var next_index = $('#photo-big .big img').attr('index')==
    $('.wait-load').length-1 ? 0
        : parseInt($('#photo-big .big img').attr('index'))+1;
    var next_dl = $('.row.pro div').eq(next_index);
    previousLoadImage(next_dl);
});
// 封装一个预加载上一张和下一张图片的方法
function previousLoadImage (children) {
    // children是所传递的dl标签
    // 所传递的dl标签就是当前显示在弹出框的图片所在的dl
    // console.dir(children);

    // 相邻的上一个dl的索引
    var prev_index = children.prev().index();
    // prev()是向上找相邻的一个元素，当找到第一个元素时，在往上
    // 找就没有了，此时prev().index() = -1
    // 加上一个判断条件当 prev_index = -1 去找最后一张
    if (prev_index == -1) {
        prev_index = $('.wait-load').length-1;
    }

    // 相邻的下一个dl的索引
    var next_index = children.next().index();
    // 同理prev()
    // 当next_index = -1的时候，去找第一张
    if (next_index == -1) {
        next_index = 0;
    }


    // 预加载上一张/下一张图片
    var prev_img = new Image();
    prev_img.src = $('.wait-load').eq(prev_index).attr('xsrc');
    var next_img = new Image();
    next_img.src = $(' .wait-load').eq(next_index).attr('xsrc');

    // 给span标签自定义一个属性src
    // 把上一张图片的src给class为left的span
    $('#photo-big .big span.left').attr('src',prev_img.src);
    // 把下一张图片的src给class为right的span
    $('#photo-big .big span.right').attr('src',next_img.src);

    // 当前图片(dl标签)的索引值
    var current_index = children.index();
    // 把当前图片的索引值保存到#photo-big .big中的img里面
    // 给img标签添加属性index
    $('#photo-big .big img').attr('index',current_index);

    // 显示页码
    $('#photo-big .big .page-index').html(current_index+1+
        '/'+$(' .wait-load').length);
}

//右侧侧边栏
$('.xuanfu a').each(function () {
    $('.xuanfu a ').click(function () {

        $(this).css({
            'background':'red',
            'color':'#fff'
        }).siblings().removeAttr('style');
        $(this).addClass('selected').siblings().removeClass('selected')
    });

});

function ding() {
    $("html,body").animate({scrollTop:"0"},1000)
}
function die() {
    $('.tans').css('display','none');
}
//底部
function sun() {
    $('.zz').removeClass('animated slideInLeft').addClass('animated slideOutLeft').css('display','none');
    $('.zx').css('display','block').removeClass('animated slideOutLeft').addClass('animated slideInLeft')
}
function wu() {
    $('.zx').removeClass('animated slideInLeft')
            .addClass('animated slideOutLeft').css('display','none');
    $('.zz').css('display','block').removeClass('animated slideOutLeft').addClass('animated slideInLeft')
}
//新闻临街小轮播

function news() {
    var height = $(".lll tr").height(); //每个li的高
    var index_end = $('.lll tr').length; //li的个数
    $(".lll").css("height",index_end*height);
    function jia() {
        $(".lll")
            .animate({
                top:-height
            },10,function(){
                $(".lll").css("top","0").children().first().appendTo(".lll")
            })
    }
    setInterval(jia,500)
}
news();


//向左
/*
(function () {
    var width = $(".teacher li").width(); //每个li的宽
    var index_end = $('.teacher li').length; //li的个数
    $(".teacher").css("width",index_end*width+41);
    function jias() {
        $(".teacher")
            .animate({
                left:-width
            },1000,function(){
                $(".teacher").css("left","0").children().first().appendTo(".teacher");
            })
    }
    var timer = setInterval(jias,1000);
//    向左点击移动
    $('.div').hover(function () {
        clearInterval(timer);
    },function () {
        timer = setInterval(jias,1000);
    });
    $('.prev').click(function () {
        clearInterval(timer);
        $(".teacher").animate({
            left: -width
        },100,function(){
            $(".teacher").css("left","0").children().first().appendTo(".teacher");
            timer = setInterval(jias,1000);
        })
    });
//    向右点击移动
    $('.next').click(function () {
        clearInterval(timer);
        $(".teacher").animate({
            left: width
        },100,function(){
            $(".teacher").css("left","0").children().last().prependTo(".teacher");
            timer = setInterval(jias,1000);
        })

    })
})();
*/
//计算钱数
function jisuan() {
    var pingfang = $('#mianji').val();
    var qian = pingfang *  653;
    var cai = qian * 42/100;
    var ren = qian * 48/100;
    var she = qian * 6/100;
    var zhi = qian * 4/100;
    $('.yu-cai').text(cai);
    $('.yu-ren').text(ren);
    $('.yu-she').text(she);
    $('.yu-zhi').text(zhi);
    $('.yu-zong').text(qian);
}

